package com.api.apigateway.controller;

import com.api.apigateway.enums.GateWayRefreshEnum;
import com.api.apigateway.mq.GatewayRefreshProducer;
import com.api.apigateway.service.RouteService;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 崔老爷
 * Date: 2024/10/18 19:37
 * @Description:
 */
@RestController
@RequestMapping("/route")
public class GateWayRouteController {

    @Resource
    private RouteService routeService;
    @Resource
    private GatewayRefreshProducer gatewayRefreshProducer;



    @GetMapping
    public Mono<List<RouteDefinition>> getGateway() {
        return routeService.getGateway();
    }

    /**
     * 路由手动刷新
     *
     * @return 是否成功：true-成功，false-失败
     */
    @GetMapping("/refresh")
    public Boolean refresh() {
        gatewayRefreshProducer.sendMessage(GateWayRefreshEnum.SUCCESS.getValue());
        return true;
    }

}
